package object;

import java.io.*;
import java.util.HashMap;

public class Stage implements Serializable {
    protected HashMap<String, String[]> addedFiles;

    public Stage() throws Exception{
        this.addedFiles = new HashMap<String, String[]>();
        this.writeObject();
    }


    public void updateStage(BaseObject obj) throws Exception{
        String [] info = new String[]{obj.getFmt(), obj.getKey(), obj.getName()};
        String key = obj.getPath();

        this.addedFiles.put(key, info);
    }

    public HashMap<String, String[]> getAddedFiles(){
        return addedFiles;
    }

    public void removeStage(String path) throws Exception{
        this.addedFiles.remove(path);
    }

    public void clearStage(){
        this.addedFiles.clear();
    }
    public void writeObject() throws Exception{
        try {

            ObjectOutputStream out =
                    new ObjectOutputStream(new FileOutputStream(".jit" + File.separator + "index"));

            out.writeObject(this);
            out.close();
        }
        catch(Exception ex){
            ex.getStackTrace();
        }
    }
    public static Stage deserialize() throws IOException {
        try{
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(".jit" + File.separator + "index"));
            return (Stage) in.readObject();
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
